package com.cn.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.api.ApiResult;
import com.cn.mapper.ShopCommentMapper;
import com.cn.mapper.ShopCommodityMapper;
import com.cn.mapper.ShopUserMapper;
import com.cn.pojo.DTO.ShopCommentDTO;
import com.cn.pojo.shop.ShopComment;
import com.cn.pojo.shop.ShopCommodity;
import com.cn.service.ShopCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 28631
* @description 针对表【shop_comment(评论表)】的数据库操作Service实现
* @createDate 2024-02-29 15:12:20
*/
@Service
public class ShopCommentServiceImpl extends ServiceImpl<ShopCommentMapper, ShopComment>
    implements ShopCommentService {


    @Autowired
    private ShopCommentMapper shopCommentMapper;

    @Autowired
    private ShopCommodityMapper shopCommodityMapper;

    @Autowired
    private ShopUserMapper shopUserMapper;

    /**
     * 评价列表信息
     * @return
     */
    @Override
    public ApiResult queryComment() {
        List<ShopCommentDTO> selectCommentList= shopCommentMapper.selectCommentList();
        return  ApiResult.success(selectCommentList);
    }

    /**
     * 修改
     * @param shopComment
     * @return
     */
    @Override
    public ApiResult updateComment(ShopCommentDTO shopCommentDTO) {
        ShopComment shopComment = new ShopComment();
        shopComment.setId(shopCommentDTO.getId());
        shopComment.setContent(shopCommentDTO.getContent());
        shopComment.setUserId(shopCommentDTO.getUserId());
        shopComment.setCommodityId(shopCommentDTO.getCommodityId());
        //修改评论信息
        int i = shopCommentMapper.updateById(shopComment);
        return ApiResult.success(i);
    }

    /**
     * 删除评论信息
     * @param id
     * @return
     */
    @Override
    public ApiResult deleteComment(Integer id) {
        return ApiResult.success(shopCommentMapper.deleteById(id));
    }
}




